package beans.factory.config.BeanPostProcessor;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import commons.beans.resume.Loggingable;
import commons.beans.resume.impl.JobSeekers;


public class BeanPostProcessorExample implements BeanPostProcessor{
	
	public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
		if(bean instanceof Loggingable){
			System.out.println("BeanPostProcessor before initialization:\t" + bean);
		}
		return bean;
	}

	public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
		if(bean instanceof Loggingable){
			System.out.println("BeanPostProcessor after  initialization:\t" + bean);
		}
		return bean;
	}
	
	public static void main(String[] args) {
		ApplicationContext ctx2 = new ClassPathXmlApplicationContext("beans/config/BeanPostProcessor/beanpostprocessor.xml");
		JobSeekers jobseekers = ctx2.getBean("jobSeekers", JobSeekers.class);
		
		System.out.println(jobseekers);
	}
}
